<html>
<head><meta charset="utf-8"><title>Getting ast::Item from ast::NodeId · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Getting.20ast.3A.3AItem.20from.20ast.3A.3ANodeId.html">Getting ast::Item from ast::NodeId</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="240464459"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Getting%20ast%3A%3AItem%20from%20ast%3A%3ANodeId/near/240464459" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> GuillaumeGomez <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Getting.20ast.3A.3AItem.20from.20ast.3A.3ANodeId.html#240464459">(May 27 2021 at 13:11)</a>:</h4>
<p>I have a <code>NodeId</code> and I want to get an <code>ast::Item</code> from it. The best I could find was how to get a <code>DefId</code>. Does anyone know a way to get an <code>ast::Item</code> from an <code>ast::NodeId</code> by any chance?</p>
<p>The code I currently have:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">fn</span> <span class="nf">visit_use_tree</span><span class="p">(</span><span class="o">&amp;</span><span class="k">mut</span><span class="w"> </span><span class="bp">self</span><span class="p">,</span><span class="w"> </span><span class="n">use_tree</span>: <span class="kp">&amp;</span><span class="nc">ast</span>::<span class="n">UseTree</span><span class="p">,</span><span class="w"> </span><span class="n">id</span>: <span class="nc">ast</span>::<span class="n">NodeId</span><span class="p">,</span><span class="w"> </span><span class="n">_nested</span>: <span class="kt">bool</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="bp">self</span><span class="p">.</span><span class="n">resolver</span><span class="p">.</span><span class="n">borrow_mut</span><span class="p">().</span><span class="n">access</span><span class="p">(</span><span class="o">|</span><span class="n">resolver</span><span class="o">|</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="n">resolver</span><span class="p">.</span><span class="n">node_id_to_def_id</span><span class="p">[</span><span class="n">id</span><span class="p">]</span><span class="w"> </span><span class="c1">// how to get ast::Item from the DefId?</span>
<span class="w">    </span><span class="p">});</span><span class="w"></span>
<span class="w">    </span><span class="n">ast</span>::<span class="n">visit</span>::<span class="n">walk_use_tree</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="w"> </span><span class="n">use_tree</span><span class="p">,</span><span class="w"> </span><span class="n">id</span><span class="p">);</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>